//
//  MessageTableViewCell.m
//  UserUse
//
//  Created by angra on 16/10/18.
//  Copyright © 2016年 CJPC. All rights reserved.
//

#import "MessageTableViewCell.h"
#import "SystemMessageModel.h"

@interface MessageTableViewCell()
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UILabel *contentLabel;
@property (nonatomic,weak)UILabel *timeLabel;
@end

@implementation MessageTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setInterface];
    }
    return self;
    
}
-(void)setInterface
{
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.text = @"支付成功通知";
    titleLabel.font = FontSize(kScaleNum(14));
    titleLabel.textColor = kColoeString(@"333333");
    [self.contentView addSubview:titleLabel];
    _titleLabel = titleLabel;
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).with.offset(kScaleNum(10));
        make.top.equalTo(self.contentView).with.offset(kScaleNum(15/2));
        make.height.equalTo(@(kScaleNum(14)));
        make.width.lessThanOrEqualTo(@(kScaleNum(200)));
    }];
    
    UILabel *contentLabel = [[UILabel alloc]init];
    contentLabel.text = @"您长沙至襄阳的行程费用已支付完成，请等待自己前来接送";
    contentLabel.font = FontSize(kScaleNum(12));
    contentLabel.textColor = kColoeString(@"666666");
    [self.contentView addSubview:contentLabel];
    _contentLabel = contentLabel;
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel);
        make.top.equalTo(titleLabel.mas_bottom).with.offset(kScaleNum(5));
        make.right.equalTo(self.contentView.mas_right).with.offset(kScaleNum(-10));
        make.height.equalTo(@(kScaleNum(12)));
    }];
    
    UILabel *timeLabel = [[UILabel alloc]init];
    timeLabel.text = @"9月5日";
    timeLabel.textAlignment = NSTextAlignmentRight;
    timeLabel.font = FontSize(kScaleNum(12));
    timeLabel.textColor = kColoeString(@"666666");
    [self.contentView addSubview:timeLabel];
    _timeLabel = timeLabel;
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(titleLabel);
        make.right.equalTo(self.contentView).with.offset(kScaleNum(-10));
        make.height.equalTo(@(kScaleNum(12)));
        make.width.equalTo(@(kScaleNum(70)));
        
    }];
    
  
}
-(void)setModel:(SystemMessageModel *)model
{
    _model = model;
    _contentLabel.text = model.content;
    _titleLabel.text = model.title;
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"MM月dd日"];
    
    // 毫秒值转化为秒
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:[model.createTime doubleValue]/ 1000.0];
    NSString* dateString = [formatter stringFromDate:date];
    _timeLabel.text = dateString;

}

@end
